package org.nicocube.airain.re.proc;

import java.util.Queue;

import org.nicocube.airain.domain.client.character.Action;
import org.nicocube.airain.domain.client.character.GameCharacter;
import org.nicocube.airain.domain.client.character.Possession;
import org.nicocube.airain.domain.client.character.Possession.Type;
import org.nicocube.airain.domain.client.gamedate.GameDate;
import org.nicocube.airain.domain.client.report.EatingActionReport;
import org.nicocube.airain.re.RuleResult;
import org.nicocube.airain.re.utils.Alea;

public class EatingProcessor extends Processor {

	public EatingProcessor(GameCharacter gc, Action action, Alea alea) {
		super(gc, action, alea);
	}

	@Override
	public RuleResult call() throws Exception {		
		GameCharacter gc = getGc();
		
		Queue<Possession> food = gc.getPossessionByType(Type.food);
		
		EatingActionReport ear = new EatingActionReport();
		RuleResult result = new RuleResult(ear,gc);
		
		if (food.size() > 0) {
			food.poll();
			GameDate current = getAction().getGameDate();
			gc.setLastEatingHour(current);
			ear.setHasFood(true);
		}
		else {
			ear.setHasFood(false);
		}
		return result;
	}

}
